package Demo;

import java.util.*;

public class Demo79 {
    public static void main(String[] args) throws Exception {
        List<PPerson> all = new ArrayList<>();
        all.add(new PPerson("oldman", 20));
        all.add(new PPerson("oldman", 21));
        all.add(new PPerson("oldman", 22));
        all.add(new PPerson("oldman", 23));
        Vector<PPerson> v = new Vector<>(all);
        Iterator<PPerson> it = all.iterator();
        while (it.hasNext()) {
            System.out.println(it.next());
        }
        System.out.println("\n");
        ListIterator<PPerson> list = all.listIterator();
        while (list.hasNext()) {
            System.out.println(list.next());
        }
        System.out.println("\n");
        while (list.hasPrevious()) {
            System.out.println(list.previous());
        }
        System.out.println("\n");
        Enumeration<PPerson> enu=v.elements();
        while (enu.hasMoreElements()){
            System.out.println(enu.nextElement());
        }

    }
}

class PPerson implements Comparable<PPerson> {
    private String name;
    private int age;

    public PPerson(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public int compareTo(PPerson p) {
        if (this.age > p.age) {
            return 1;
        } else if (this.age < p.age) {
            return -1;
        } else {
            return this.name.compareTo(p.name);
        }

    }

    @Override
    public String toString() {
        return "PPerson{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @SuppressWarnings("all")
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (this instanceof PPerson) {
            return true;
        }
        PPerson p = (PPerson) obj;
        return this.age == ((PPerson) obj).age && this.name.equals(((PPerson) obj).name);
    }
}

class qqClass extends PPerson {
    public qqClass(String name, int age) {
        super(name, age);
    }
}